package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * packageName com.sky.controller.admin
 *
 * @author fenglai
 * @version JDK 11
 * @className DishController
 * @date 2023/12/10
 * @description TODO
 */

@RestController
@RequestMapping("/admin/dish")
@Api("菜品功能模块")
@Slf4j
public class DishController {
    @Autowired
    DishService dishService;


    /**
     * @param dto: return Result<PageResult>
     * @author fenglai
     * @date 2023/12/15 10:05
     * @description 菜品分页查询功能
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> pageSelectDish(DishPageQueryDTO dto) {

        log.info("正在执行菜品分页查询............查询信息为:{}", dto);

        PageResult p = dishService.pageSelectDish(dto);


        return Result.success(p);
    }

    /**
     * @param categoryId: return Result<List<Dish>>
     * @author fenglai
     * @date 2023/12/15 10:14
     * @description 根据分类id查询菜品功能
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> selectDishByCategoryId(Long categoryId) {

        log.info("正在执行根据分类id查询菜品..............分类id为{}", categoryId);

        List<Dish> dishes = dishService.selectDishByCategoryId(categoryId);


        return Result.success(dishes);

    }

/**
 * @param id:
 * return Result<DishVO>
 * @author fenglai
 * @date 2023/12/15 10:27
 * @description 根据id查询菜品功能
 */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> selectDishById(@PathVariable Long id) {

        log.info("正在执行根据id查询菜品..............菜品id为:", id);

        DishVO dishVO = dishService.selectDishById(id);

        return Result.success(dishVO);

    }

    /**
     * @param dto:
     * return Result
     * @author fenglai
     * @date 2023/12/15 10:41
     * @description 新添菜品功能
     */
    @PostMapping
    @ApiOperation("新添菜品功能")
    public Result addDish(@RequestBody DishDTO dto){

        log.info("正在执行新添菜品的功能...........菜品信息为:{}",dto);

        dishService.addDish(dto);

        return Result.success();

    }

/**
 * @param dto:
 * return Result
 * @author fenglai
 * @date 2023/12/15 12:03
 * @description 修改菜品的功能
 */
    @PutMapping
    @ApiOperation("修改菜品的功能")
    public Result updateDish(@RequestBody DishDTO dto){

        log.info("正在执行修改菜品的功能...............修改信息为:{}",dto);


        dishService.updateDish(dto);

        return Result.success();
    }

    /**
     * @param status:
     * @param id:
     * return Result
     * @author fenglai
     * @date 2023/12/15 11:44
     * @description 菜品起售、停售功能
     */
    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售、停售")
    public Result updateDishStatus(@PathVariable Integer status,Long id){

        log.info("正在执行菜品起售、停售的功能.............状态为:{},菜品id为:{}",status,id);

        dishService.updateDishStatus(status,id);

        return Result.success();

    }

    /**
     * @param ids:
     * return Result
     * @author fenglai
     * @date 2023/12/15 12:03
     * @description 批量删除菜品功能
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品功能")
    public Result deleteDish(@RequestParam List<Long> ids){

        log.info("正在执行批量删除菜品功能.......删除的菜品id为:{}",ids);

        dishService.deleteDish(ids);

        return Result.success();
    }



}